Imports ToolKitVB
Imports ToolKitVB.Web.UI.Javascript
<System.Web.UI.ParseChildren(True, "Text"), _
System.Drawing.ToolboxBitmap(GetType(ToolKitLabel), _
 "Web.UI.WebControls.Label.ico")> _
Public Class ToolKitLabel
    Inherits WebControls.Label
    Implements IToolKit
    Enum AutoFormatEnum
        None
        [Integer]
        Currency
        [Decimal]
    End Enum
    Private _AutoFormat As AutoFormatEnum = AutoFormatEnum.None
    ''' <summary>
    ''' Makes user unable to type in incorrect values.
    ''' </summary>
    ''' <remarks></remarks>
    Public Property AutoFormat() As AutoFormatEnum
        Get
            Return _AutoFormat
        End Get
        Set(ByVal value As AutoFormatEnum)
            _AutoFormat = value
        End Set
    End Property

    Private _AddToJavascript As Boolean = False
    ''' <summary>
    ''' Makes TextBox Available in AddToJavascript.
    ''' </summary>
    ''' <remarks></remarks>
    Public Property AddToJavascript() As Boolean
        Get
            Return _AddToJavascript
        End Get
        Set(ByVal value As Boolean)
            _AddToJavascript = value
        End Set
    End Property
    Private _OnMouseOver As String = ""
    Public Property OnMouseOver() As String
        Get
            Return _OnMouseOver
        End Get
        Set(ByVal value As String)
            _OnMouseOver = value
        End Set
    End Property
    Private _OnMouseOut As String = ""
    Public Property OnMouseOut() As String
        Get
            Return _OnMouseOut
        End Get
        Set(ByVal value As String)
            _OnMouseOut = value
        End Set
    End Property

    Public Overrides Property Text() As String
        Get
            Return MyBase.Text
        End Get
        Set(ByVal value As String)
            If _AutoFormat = AutoFormatEnum.Currency Then
                If value = "" Then value = "0.00"
                MyBase.Text = FormatCurrency(value)
            ElseIf _AutoFormat = AutoFormatEnum.Decimal Then
                If value = "" Then value = "0"
                MyBase.Text = CType(value, Decimal).ToString
            ElseIf _AutoFormat = AutoFormatEnum.Integer Then
                If MyBase.Text = "" Then value = "0"
                MyBase.Text = CType(value, Int64).ToString
            End If
        End Set
    End Property
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        MyBase.OnLoad(e)
    End Sub
    Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
        MyBase.OnPreRender(e)
        If _AddToJavascript Then
            DirectCast(Me.Page, Web.UI.ToolKitPage).Javascript.RegisterControl(Me)
        End If
        If _OnMouseOver <> "" Then Me.Attributes.Add("onmouseover", ToolKitTools.WrapErrorHandler(_OnMouseOver, Me.ID & " OnMouseOver"))
        If _OnMouseOut <> "" Then Me.Attributes.Add("onmouseout", ToolKitTools.WrapErrorHandler(_OnMouseOut, Me.ID & " OnMouseOut"))
    End Sub
    Public Property ToolKitPage() As Web.UI.ToolKitPage
        Get
            Return DirectCast(MyBase.Page, Web.UI.ToolKitPage)
        End Get
        Set(ByVal value As Web.UI.ToolKitPage)
            MyBase.Page = value
        End Set
    End Property
    Public Overrides Function ToString() As String Implements IToolKit.ToString
        Return Text
    End Function


End Class
